import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import i18n from '@/lang'
// import asyncRoutes from '@/router/modules/index'
Vue.use(Router)
/* Layout */

// 静态路由
// 不需要权限
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    // 路由源
    meta: {
      noLogin: true
    }
  },

  {
    path: '/',
    component: Layout,
    // 重定向
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: i18n.t('route.dashboard'), icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
    // 路由源
    meta: {
      noLogin: true
    }
  }
  // 在测试的时候使用 权限设置好后注释
  // ...asyncRoutes
  // 404 路由匹配
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// 重置路由 固定写法
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
